
ProDefinitionUserForm=Ext.extend(Ext.Window,{
	//内嵌FormPanel
	formPanel:null,
	//构造函数
	constructor:function(_cfg){
		Ext.applyIf(this,_cfg);
		//必须先初始化组件
		this.initUIComponents();
		ProDefinitionUserForm.superclass.constructor.call(this,{
			id:'ProDefinitionUserFormWin',
			layout:'fit',
			items:this.formPanel,
			modal:true,
			height:200,
			width:600,
			maximizable:false,
			title:"流程通知人员设置－" + this.name,
			buttonAlign : 'center',
			buttons:this.buttons
		});
	},//end of the constructor
	//初始化组件
	initUIComponents:function(){
		this.formPanel=new Ext.FormPanel({
				layout : 'form',
				bodyStyle: 'padding:10px 10px 10px 10px',
				border:false,
				url : __ctxPath + '/flow/saveUserProDefinition.do',
				id : 'ProDefinitionUserForm',
				defaults : {
					anchor : '98%,98%'
				},
				defaultType : 'textfield',
				items : [{
							name : 'defId',
							xtype:'hidden',
							value : this.defId == null ? '' : this.defId
						},{
								xtype:'container',
								defaultType:'textfield',
								style:'padding-left:0px;margin-top:5px;',
								layout:'column',
								items:[
									{
										xtype:'hidden',
										id:'userIds',
										name:'userIds'
									},
									{
										xtype:'label',
										text:'通知人员：',
										width:70
									},
									{
										id : 'userNames',
										width:350,
										height:100,
										xtype:'textarea',
										allowBlank:true,
										style:'padding-left:5px;',
										readOnly:true
									}, {
										xtype:'container',
										border:true,
										width:100,
										heigth:30,
									    items:[{
											xtype : 'button',
											iconCls:'btn-mail_recipient',
											text : '添加通知人 ',
											width:80,
											handler :function(){
													UserSelector.getView(function(userIds,fullnames){
												    		  var userId=Ext.getCmp('userIds');
												    		  var userFullname=Ext.getCmp('userNames');
												    		  if(userId.getValue()!=''&&userFullname.getValue()!=''){
												    			  var stId=(userId.getValue()+',').concat(userIds);
												    			  var stName=(userFullname.getValue()+',').concat(fullnames);
												    			  var ids=uniqueArray(stId.split(','));
												    			  var names=uniqueArray(stName.split(','));
												    			  userId.setValue(ids.toString());
													    		  userFullname.setValue(names.toString());			   		  
												    		  }else{
												    			  userId.setValue(userIds);
													    		  userFullname.setValue(fullnames);
												    		  }
												    	   }).show();
									    	}
									    }, {
											xtype : 'button',
											text : '清除通知人',
											iconCls:'btn-del',
											width:80,
											handler : function() {
													Ext.Msg.confirm('信息确认', '确定清除通知人吗？', function(btn) {
														if (btn == 'yes') {
															var name = Ext.getCmp('userNames');
															var id = Ext.getCmp('userIds');
															name.reset();
															id.reset();
														}
													});
												
										   }}]
								       }
									]
						}
																								
						]
			});
		//加载表单对应的数据	
		if (this.defId != null && this.defId != 'undefined') {
			Ext.Ajax.request({
								url:__ctxPath+'/flow/getUserProDefinition.do',
								params:{defId:this.defId},
								method:'POST',
								success:function(response,options){
									 var jsonData = Ext.util.JSON.decode(response.responseText);
									 var res = jsonData.data;
									 var userIds = res.userIds;
									 var userNames = res.userNames;
									 Ext.getCmp("userNames").setValue(userNames);
									 Ext.getCmp("userIds").setValue(userIds);
								},
								failure:function(response,options){
									Ext.ux.Toast.msg('操作信息','操作出错，请联系管理员！');
								}
							});
			
		}
		//初始化功能按钮
		this.buttons=[{
				text : '保存',
				iconCls : 'btn-save',
//				hidden:!(isGranted('_ProjectRushMoneyPayAgreeEdit')),
				handler :this.save.createCallback(this.formPanel,this)
			},{
				text : '取消',
				iconCls : 'btn-cancel',
//				hidden:!(isGranted('_ProjectRushMoneyPayAgreeEdit')),
				handler : this.cancel.createCallback(this)
			}];
	},//end of the initcomponents
	
	/**
	 * 重置
	 * @param {} formPanel
	 */
	reset:function(formPanel){
		formPanel.getForm().reset();
	},
	/**
	 * 取消
	 * @param {} window
	 */
	cancel:function(window){
		window.close();
	},
	/**
	 * 保存记录
	 */
	save:function(formPanel,window){
		if (formPanel.getForm().isValid()) {
			formPanel.getForm().submit({
				method : 'POST',
				waitMsg : '正在提交数据...',
				success : function(fp, action) {
					Ext.ux.Toast.msg('操作信息', '成功保存信息！');
					window.close();
				},
				failure : function(fp, action) {
					Ext.MessageBox.show({
								title : '操作信息',
								msg : '信息保存出错，请联系管理员！',
								buttons : Ext.MessageBox.OK,
								icon : Ext.MessageBox.ERROR
							});
					window.close();
				}
			});
		}
	}//end of save
	
});